package se.sudoku;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.TextView;


public class SudokuWaitForOpponent extends Activity {

	//SUDOKUMENU ITEMS
	private PopupWindow wait;
	private Button waitmenu_btn_1;
	private Activity activity;
	private TextView waitText;
	
	//constructor
	public SudokuWaitForOpponent(Context c) {
		activity = (Activity) c;
		//popup window
		wait = new PopupWindow(View.inflate(c, R.layout.sudokuwaitforopponent, null), LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, true);
		//buttons
		waitmenu_btn_1 = (Button)wait.getContentView().findViewById(R.id.waitforopponent_tomain);
		waitmenu_btn_1.setOnClickListener(sudukoWaitForOpponentListener);
	}
	
	//toggle windows
	public void toggleWaitForOpponentWindow(String ip){

		waitText = (TextView)wait.getContentView().findViewById(R.id.sudokuwait_text);
	
		waitText.setText("Your IP: " + ip);
			
    	if(!wait.isShowing()){
    		wait.showAtLocation(activity.findViewById(R.id.sudokuview), Gravity.CENTER, 0, 0);
    	}
    	else{
    		wait.dismiss();
    	}
    	Log.v("toggle", "end");
    }
	
	public void closeWaitForOpponentWindow(){
		
    	if(!wait.isShowing()){
    		wait.showAtLocation(activity.findViewById(R.id.sudokuview), Gravity.CENTER, 0, 0);
    	}
    	else{
    		wait.dismiss();
    	}
		
	}
	
	//button Listner
	private OnClickListener sudukoWaitForOpponentListener = new OnClickListener() {
		public void onClick(View v) {
			
			//to main menu
			if(v==waitmenu_btn_1){
				closeWaitForOpponentWindow();
				activity.setResult(RESULT_CANCELED);
				activity.finish();
			}
	    }
	};
}